package br.com.linkcom.sined.util;

import javax.servlet.http.HttpServletRequest;

import br.com.linkcom.neo.authorization.User;
import br.com.linkcom.neo.core.standard.Neo;
import br.com.linkcom.neo.core.web.NeoWeb;
import br.com.linkcom.sined.geral.bean.Usuario;

public class SinedUtil {
	
	public static final String SINED_CACHE_MODULES = "sined_cache_menu"; 
	public static final String SINED_CACHE_ACAOPERMISSION = "sined_cache_acaopermissions";
	
	public static Usuario getUsuarioLogado(){
		User user = Neo.getRequestContext().getUser();
		if(user instanceof Usuario){
			return (Usuario) user;
		} else {
			return null;
		}
	}
	
	public static String getClientName() {
		HttpServletRequest servletRequest = NeoWeb.getRequestContext().getServletRequest();
		String url = servletRequest.getRequestURL().toString();
		
		String[] urlDividida = url.split("/");
		
		String servidor = urlDividida[2];
		String contexto = urlDividida[3];
		
		urlDividida = servidor.split(".");
		if(urlDividida.length==0){
			urlDividida = servidor.split(":");
			if(urlDividida.length>0){				
				servidor = urlDividida[0];
			}
		}
				
		return servidor+"_"+contexto;
	}
	
	public static User getUserLogado(){
		return NeoWeb.getUser();
	}
}